#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

// 2958. 最多 K 个重复元素的最长子数组
// https://leetcode.cn/problems/length-of-longest-subarray-with-at-most-k-frequency/description/

class Solution {
public:
    int maxSubarrayLength(vector<int>& nums, int k) {
        unordered_map<int, int> freq;
        int left = 0;
        int ans = 0;
        int n = nums.size();
        for (int i = 0; i < n;i++){
            int curNum = nums[i];
            freq[curNum]++;
            while(freq[curNum] > k){
                freq[nums[left++]]--;
            }
            ans = max(ans, i - left + 1);
        }
        return ans;
    }
};

int main()
{
    return 0;
}